package com.api.shopapi.mapper;


import com.api.shopapi.entity.SendMessage;
import com.api.shopapi.entity.dto.SendMessageDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface SendMessageMapper {

    @Insert("insert into send_message " +
            "(SendMessageCode,MsgType,MsgContent,AskIsHear,AskIsJoin,CreateTime,StaffCode,GovernmentCode) values " +
            "(#{sendMessage.SendMessageCode},#{sendMessage.MsgType},#{sendMessage.MsgContent},#{sendMessage.AskIsHear}," +
            "#{sendMessage.AskIsJoin},#{sendMessage.CreateTime},#{sendMessage.StaffCode},#{sendMessage.GovernmentCode})")
    int insert(@Param("sendMessage") SendMessage sendMessage);

    @Select("select * from send_message where SendMessageCode=#{sendMessageCode} limit 1")
    SendMessage getBySendMessageCode(@Param("sendMessageCode") String sendMessageCode);

    @Select("select m.*,Count(*) sendCount from send_message m, send_message_item i " +
            "where GovernmentCode=#{governmentCode} " +
            "and m.SendMessageCode= i.SendMessageCode " +
            "and (m.CreateTime between #{startTime} and #{endTime}) " +
            "GROUP BY i.SendMessageCode " +
            "order by m.CreateTime desc")
    List<SendMessageDTO> getPageList(@Param("startTime") String startTime, @Param("endTime") String endTime,@Param("governmentCode") String governmentCode);
}
